<?php
include '../database/connection.php';
include '../libs/secure.php';
sec_session_start(); // Our custom secure way of starting a php session. 
 
if(isset($_POST['name'], $_POST['p'])) { 
   $name = $_POST['name'];
   $password = $_POST['p']; // The hashed password.
   if(login($name, $password, $mysqli) == true) {
      // Login success
      echo 'Success: You have been logged in!';
      writeLog($conn, $_SESSION['iduser'], "Log - in");
      header('Location: http://localhost/freeappstore/index.php');
   } else {
      // Login failed
      header('Location: http://localhost/freeappstore/index.php?error=1');
   }
} else { 
   // The correct POST variables were not sent to this page.
   echo 'Invalid Request';
   
}
?>
